package com.apollow.oschina.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.apollow.oschina.R;
import com.apollow.oschina.bean.DetailTweetBean;
import com.apollow.oschina.bean.TweetBean;
import com.apollow.oschina.protocol.TweetDetailProtocol;
import com.apollow.oschina.util.PicassoUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by Administrator on 2017/1/19.
 * 项目名:    OsChina
 * 包名:      com.apollow.oschina.ui
 * 文件名:    TweetDetailActivity
 * 创建者:    LXF
 * 创建时间:   ${DATA}0:02
 * 描述:     TODO
 */
public class TweetDetailActivity extends AppCompatActivity {
    @BindView(R.id.iv_use)
    CircleImageView mIvUse;
    @BindView(R.id.tv_name)
    TextView mTvName;
    @BindView(R.id.tv_desc)
    TextView mTvDesc;
    @BindView(R.id.iv_desc)
    ImageView mIvDesc;
    @BindView(R.id.tv_discuss_count)
    TextView mTvDiscussCount;
    @BindView(R.id.tv_comment)
    TextView mTvComment;
    private TweetDetailProtocol mProtocol;
    public TweetBean data;
    private TweetBean mTweet;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.item_tweet_hotdetail);
        ButterKnife.bind(this);
        initData();
    }
    private void initData() {
        String uid = String.valueOf(getIntent().getIntExtra("UID", 6066159));
        mProtocol = new TweetDetailProtocol();
        mProtocol.setUid(uid);
        new Thread(new Runnable() {
            @Override
            public void run() {
                DetailTweetBean data = mProtocol.getData();
                mTweet = data.getTweet();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        PicassoUtil.displayImage(TweetDetailActivity.this, mTweet.getPortrait(), R.drawable.userimage, mIvUse);
                        mTvName.setText(mTweet.getAuthor());
                        mTvDesc.setText(mTweet.getBody());
                        if (!TextUtils.isEmpty(mTweet.getImgSmall())) {
                            PicassoUtil.displayImage(TweetDetailActivity.this, mTweet.getImgSmall(), R.drawable.userimage, mIvDesc);
                        }
                        mTvDiscussCount.setText(mTweet.getCommentCount() + "");
                    }
                });
            }
        }).start();

    }
}
